package initization

import (
	"github.com/google/uuid"
	"github.com/hashicorp/consul/api"
	"go.uber.org/zap"
)

func init() {
	ZapInit()
	//ConsulInit()
}
func ZapInit() {
	config := zap.NewDevelopmentConfig()
	config.OutputPaths = []string{
		"./srv.log",
		"stdout",
	}
	build, _ := config.Build()
	zap.ReplaceGlobals(build)
}
func ConsulInit() {
	//consul := tools.Consul{
	//	Host: "117.27.231.246",
	//	Port: 8500,
	//}
	//newConsul := tools.NewConsul(consul.Host, consul.Port)
	a := api.Config{
		Address: "117.27.231.246:8500",
	}
	client, _ := api.NewClient(&a)
	registration := api.AgentServiceRegistration{
		ID:      uuid.NewString(),
		Name:    "user_srv",
		Tags:    []string{"123"},
		Port:    50051,
		Address: "127.0.0.1",
	}
	err := client.Agent().ServiceRegister(&registration)
	if err != nil {
		zap.S().Error("注册失败")
		return
	}
	zap.S().Info("注册成功")
}
